// pages/zxDetail/zxDetail.js
var common = require("../../utils/common.js");
//index.js
//获取应用实例
const app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    index: -1, //第几条
    length: 10,
    total: 0, //共多少条
    adviserList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     var id=options.id;
     this.setData({
       id:id
     });
    var that = this;
    that.getInformation();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },


  getInformation: function () {
    //获取资讯信息
    var that = this;
    that.setData({
      loading: false,
      canIUse: false,
      ls: false
    });

    if (app.globalData.isGoBack) {
      //页面返回
      that.setData({
        index: -1, //第几条
        length: 10,
        total: 0,
        adviserList: [],
      })
      var index = that.data.index;
      var length = that.data.length;
    } else {
      var index = that.data.index;
      var length = that.data.length;
    }
    if (index <= that.data.total) {
      index++;
      common.ajaxPost(
        'portal/wlpAdvisory/queryWlpAdvisoryPageList.action', {
          start: index,
          length: length,
          bid: app.globalData.bid,
          id:that.data.id
        },
        function (res) {
          console.log(res);
          if (res && res.length > 0) {
            var list = that.data.adviserList;
            list = list.concat(res.data);

            var article = res.data[0].content;
            WxParse.wxParse('article', 'html', article, that, 5);

            that.setData({
              adviserList: list,
              total: res.recordsTotal,
              index: that.data.index + res.length,
              loading: false,
              canIUse: false,
            })
            if (res.recordsTotal == 0) {
              wx.showToast({
                title: '暂无数据',
                icon: 'none'
              })
            }
          } else {
            wx.showToast({
              title: '没有更多了',
              icon: 'none'
            })
          }
        }
      )
    }
  }

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  
  // }
})